package za.um.td.main;

import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.logging.Logger;

import za.um.td.state.BasicGameStateSingleton;
import za.um.td.state.MainStateNode;

import com.jme.bounding.BoundingSphere;
import com.jme.math.Vector3f;
import com.jme.scene.shape.Box;
import com.jme.util.GameTaskQueueManager;
import com.jmex.editors.swing.settings.GameSettingsPanel;
import com.jmex.game.StandardGame;
import com.jmex.game.state.DebugGameState;
import com.jmex.game.state.GameStateManager;

public class TowerDefenseMain 
{
	private static final Logger LOG = Logger.getLogger(TowerDefenseMain.class.getName());
	// TODO: Think of a proper name
	public static final String GAME_NAME = "Tower Defense";

	public static void main(String[] args) {
		
		try {
			BasicGameStateSingleton.game = new StandardGame(GAME_NAME);
			
			// comment out to remove debug
			//System.setProperty("jme.stats", "set"); //debug
			
			if (GameSettingsPanel.prompt(BasicGameStateSingleton.game.getSettings())) {
				BasicGameStateSingleton.game.start();
				
				GameTaskQueueManager.getManager().update(new Callable<Void>() {

					public Void call() throws Exception {
						MainStateNode mainState = MainStateNode.getInstance();
						
						GameStateManager.getInstance().attachChild(mainState);
						mainState.setActive(true);
						
						//comment out to remove debug
						/*DebugGameState debugState = new DebugGameState();
						debugState.setName("DEBUGSTATE");
						LOG.log(Level.INFO,"debugState.getName()="+debugState.getName());
						GameStateManager.getInstance().attachChild(debugState);
						debugState.setActive(true);
						*/

						return null;
					}
				});
			}
		} catch (Throwable e) {
			e.printStackTrace();
			LOG.log(Level.SEVERE, e.getMessage());
			System.exit(1);
		}
	}
}
